package com.kaishengit.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class ReadExcel {

	public static void main(String[] args) throws FileNotFoundException, IOException {
		
		Workbook wb = new HSSFWorkbook(new FileInputStream("C:/import/contacts.xls"));
		
		Sheet st = wb.getSheetAt(0);
		
		for (int i = 1; i <= st.getLastRowNum(); i++) {
			Row row = st.getRow(i);
			for (int j = 0; j < row.getLastCellNum(); j++) {
				Cell c = row.getCell(j);
				if(c != null) {
					if(c.getCellType() == Cell.CELL_TYPE_STRING) {
						System.out.print(c.getStringCellValue() + "\t");
					} else if(c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
						System.out.print(c.getNumericCellValue() + "\t");
					}
					
				}
			}
			System.out.println();
		}
	}
}
